#include <iostream>

using namespace std;

class AbstractFruit
{
public:
	virtual void fruitName() = 0;
};

class Apple : public AbstractFruit
{
public:
	virtual void fruitName()
	{
		cout << "apple" << endl;
	}
};

class Banana : public AbstractFruit
{
public:
	virtual void fruitName()
	{
		cout << "Banana" << endl;
	}
};

class AbstractFactory
{
public:
	virtual AbstractFruit *createFruit() = 0;
};

class AppleFactory : public AbstractFactory
{
public:
	virtual AbstractFruit *createFruit()
	{
		return new Apple;
	}
};

class BananaFactory : public AbstractFactory
{
public:
	virtual AbstractFruit *createFruit()
	{
		return new Banana;
	}
};


void functionTest()
{
	AbstractFactory *furitFactory = new AppleFactory;
	AbstractFruit *fruit = furitFactory->createFruit();
	fruit->fruitName();

	delete furitFactory;
	delete fruit;

	furitFactory = new BananaFactory;
	fruit = furitFactory->createFruit();
	fruit->fruitName();

	delete furitFactory;
	delete fruit;
}

int main()
{
	functionTest();

	system("pause");
	return 0;
}